package com.veng.springbootdemo.service;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

@Service
public class FileUploadLocalService implements FileUploadService {
    @Override
    public String upload(MultipartFile file) throws IOException {
        String filename = file.getResource().getFilename();
        String pathname = "E:\\img\\";
        File new_dir = new File(pathname);
        if (!new_dir.exists()) {
            new_dir.mkdirs();
        }
        File new_file = new File(pathname+filename);
        if (!new_file.exists()) {
            new_file.createNewFile();
        }
        FileOutputStream fileOutputStream = new FileOutputStream(new_file);
        fileOutputStream.write(file.getBytes());
        fileOutputStream.close();
        return "true";
    }
}
